package com.fare.taluo.core.domain.system.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.dayatang.hibernate.EntityRepositoryHibernate;
import com.fare.taluo.core.domain.system.RegisterCreateCodeInfoEntityRepository;
import com.fare.taluo.core.domain.system.RegistercodeEntity;

@Repository
public class RegisterCreateCodeEntityRepositoryImpl extends EntityRepositoryHibernate implements RegisterCreateCodeInfoEntityRepository{

	@Override
	public List<RegistercodeEntity> checkCode(String code, String habaseKey) {

		StringBuffer sbf=new StringBuffer("from RegistercodeEntity fm where 1=1 ");
		List<Object> list = new ArrayList<Object>();
		sbf.append(" and fm.hbaseKey= ? ");
		list.add(habaseKey);
		sbf.append(" and fm.registerCode = ? ");
		list.add(code);
		sbf.append(" and fm.effectiveDate >= ? ");//'yyyy-mm-dd hh24:mi:ss'  yyyy-MM-dd hh:MI:ss
		list.add(new Date());
		
		List<RegistercodeEntity> lists=super.find(sbf.toString(),list.toArray(),RegistercodeEntity.class);
		return lists;
	}

	@Override
	public RegistercodeEntity getCodeDateByCode(String code) {
		StringBuffer sbf=new StringBuffer("from RegistercodeEntity fm where 1=1 ");
		List<Object> list = new ArrayList<Object>();
		sbf.append(" and fm.registerCode= ? ");
		list.add(code);
		
		List<RegistercodeEntity> lists=super.find(sbf.toString(),list.toArray(),RegistercodeEntity.class);
		RegistercodeEntity re=null;
		if(lists.size()>0){
			re =lists.get(0);
		}
		return re;
	}

	@Override
	public List<RegistercodeEntity> findByCode(String code) {
		StringBuffer sbf=new StringBuffer("from RegistercodeEntity fm where 1=1 ");
		List<Object> list = new ArrayList<Object>();
		if(code!=null  && !code.equals("")){
			sbf.append(" and fm.carrierKey= ? ");
			list.add(code);
		}
		
		sbf.append(" order by fm.effectiveDate desc");
		List<RegistercodeEntity> lists=super.find(sbf.toString(),list.toArray(),RegistercodeEntity.class);
		
		return lists;
	}


}
